package view;

import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.Box;

/**
 * A TrackListPanel contains a list of TrackPanels vertically arranged.
 * @author Hedja
 */
public class TrackListPanel extends ScrollableListPanel {

	private Box emptySpace;

	public TrackListPanel() {
		this.setOpaque(false);
		this.setLayout(new GridLayout(0,1,0,1));

		emptySpace = Box.createHorizontalBox();
		this.add(emptySpace);
	}

	public void removeTrackPanel(int trackIndex) {
		this.remove(trackIndex);
		int end = this.getComponentCount()-1;
		for(int i = trackIndex; i < end; i++) {
			//Adjust alternating colours.
			this.getComponent(i).setBackground(new Color(0xFEFEFE-0x222222*(i%2)));
		}
	}

	public void addTrackPanel(TrackPanel trackPanel) {
		this.remove(emptySpace);
		int i = this.getComponentCount();
		trackPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, Color.BLACK));
		trackPanel.setBackground(new Color(0xFEFEFE-0x222222*(i%2)));
		this.add(trackPanel);
		this.add(emptySpace);
	}

	public void highlightColumn(int columnIndex) {
		//Highlight the given column on all the track panels.
		for(int i = 0; i < this.getComponentCount(); i++) {
			Component c = this.getComponent(i);
			if(c instanceof TrackPanel) {
				((TrackPanel)c).highlightColumn(columnIndex);
			}
		}
	}
}
